// pages/register/register.js
const app = getApp()

Page({
  data:{
    useId:"",
    userName:"",
    password:"",
    isteacher:true,
    message:"",
    isRemember: false,

    warnToast: false,
    hideWarnToast: false
  },

  useIdInput(e){
    this.setData({
      useId: e.detail.value
    })
  },

  userNameInput(e){
    this.setData({
      username: e.detail.value
    })
  },

  pawInput(e){
    this.setData({
      password: e.detail.value
    })
  },

  isteacher(e){
    this.setData({
      isteacher: e.detail.value
    })
  },

  formSubmit(e) {
    console.log('form发生了submit事件，携带数据为：', this.data)
    let{useId,userName,password,isteacher} = this.data;
    let postData = {
      useId:this.data.useId,
      userName:this.data.userName,
      password:this.data.password,
      isteacher:this.data.isteacher 
    }
    postData = {...this.data}
    postData = {useId,userName,password,isteacher}

    wx.request({
      url: 'http://localhost/public/index/Register/register',
      method: "POST",
      data: postData,
      success: ({data}) => {
        console.log(data);
        console.log(data.status);
        if(data.status === 'success'){
          console.log(data);
          wx.navigateTo({
            url: '/pages/index/index',
          })
        }else{
          this.setData({
            warnToast: true,
            message:data.message
          });
          setTimeout(() => {
            this.setData({
                hidewarnToast: true,
            });
            setTimeout(() => {
              this.setData({
                  warnToast: false,
                  hidewarnToast: false,
              });
            }, 300);
          }, 3000);
          console.log(data.message);
        }
      },
      fail:(err)=> {
        console.log(err);
      }
    })
  },

  formReset(e) {
    console.log('form发生了reset事件，携带数据为：', e.detail.value)
    this.setData({
      chosen: ''
    })
  }
})